grammar TreeExpr;
options {
    output=AST;
    ASTLabelType=CommonTree;
}
tokens{ STATLIST; }

@members {

}


ID  :   ('a'..'z'|'A'..'Z')+ ;
INT :   '0'..'9'+ ;
NEWLINE:'\r'? '\n' ;
WS  :   (' '|'\t')+ { $channel=HIDDEN; } ;
MULT:	'*';
ASSIGN:	'=';
PLUS:	'+';
MINUS:	'-';

prog:   ( stat {System.out.println($stat.tree.toStringTree());} )+ -> ^(STATLIST (stat)+) ;

stat:   expr NEWLINE        -> expr
    |   ID ASSIGN expr NEWLINE -> ^(ASSIGN ID expr)
    |   NEWLINE             ->
    ;

expr:   multExpr ((PLUS^|MINUS^) multExpr)*
    ; 

multExpr
    :   atom (MULT^ atom)*
    ; 

atom:   INT 
    |   ID
    |   '('! expr ')'!
    ;




